home *** CD-ROM | disk | FTP | other *** search
/ developer.apple.com / developer.apple.com.tar / developer.apple.com / tools / OptimizationExample.dmg / Optimization Example / test.c < prev    next >
C/C++ Source or Header  |  2004-07-13  |  1KB  |  64 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. unsigned int doWhileWithReturn( void );
  5. void arrayAssignmentLoop( void );
  6. double doubleTest( void );
  7.  
  8. int main( void ) {
  9.    unsigned int   result;
  10.    double doubleResult;
  11.    
  12.    arrayAssignmentLoop();
  13.    
  14.    result = doWhileWithReturn();
  15.  
  16.    printf( "doWhileWithReturn returned %d\n", result );
  17.  
  18.    doubleResult = doubleTest();
  19.  
  20.    printf( "doubleTest returned %lf\n", doubleResult );
  21.  
  22.    return 0;
  23. }
  24.  
  25. void arrayAssignmentLoop( void ) {
  26.    unsigned int count = 10;
  27.    unsigned int array[ 10 ], item = 0;
  28.    
  29.    do {
  30.       array[ item++ ] = count;
  31.       count--;
  32.    } while ( count > 0 );
  33. }
  34.  
  35. unsigned int doWhileWithReturn( void ) {
  36.    unsigned int i = 100;
  37.    unsigned int result = 0;
  38.    unsigned int a = 31, b = 2, c = 99;
  39.  
  40.    do {
  41.       result += a * b;
  42.       c = a * b;
  43.    } while ( i-- > 0 );
  44.    
  45.    c = a * b;
  46.    
  47.    return result;
  48. }
  49.  
  50. double doubleTest( void ) {
  51.    const unsigned int limit = 100;
  52.    double array[ limit ][ limit ], sum = 0;
  53.    unsigned int i, j;
  54.    
  55.    for ( i = 0; i < limit; i++ ) {
  56.       for ( j = 0; j < limit; j++ ) {
  57.          array[ i ][ j ] = i;
  58.          sum += array[ i ][ j ];
  59.       }
  60.    }
  61.  
  62.    return sum;
  63. }
  64.